package com.hex.ds.hdrs.starter;

import com.hex.ds.hdrs.security.ESAPIConfiguration;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.SecurityConfiguration;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.web.WebApplicationInitializer;

@EnableRetry
@SpringBootApplication
public class HdrsServiceStarterApplication extends SpringBootServletInitializer implements
        WebApplicationInitializer {
    public static void main(String[] args) {
        final ConfigurableApplicationContext run = SpringApplication.run(HdrsServiceStarterApplication.class, args);
        espiConfigSetting(run);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(HdrsServiceStarterApplication.class).bannerMode(Banner.Mode.OFF);
    }

    /**
     * @Method: espiConfigSetting <br>
     * @Param: [run] <br>
     * @Return: void <br>
     * @Description：<br>
     * @Author： gc.zuo<br>
     * @Date： 2022/6/7 11:32 <br>
     * @Version： V1.0<br>
     */
    private static void espiConfigSetting(ConfigurableApplicationContext run) {
        final String esapiConfigPath = run.getEnvironment().getProperty("config-path.esapi");
        ESAPIConfiguration.setEsapiConfigPath(esapiConfigPath);
        final SecurityConfiguration instance = new ESAPIConfiguration();
        ESAPI.override(instance);
    }

}
